<template>
  <div class="content-box">
    <nav-title title="入公司前工作经历" />
    
    <edit-date-line :important="true" label="开始时间" v-model="expwork.startDt"></edit-date-line>
    <edit-date-line :important="true" label="结束时间" v-model="expwork.endDt"></edit-date-line>
    <edit-line :important="true" label="工作单位" v-model="expwork.cCompany"></edit-line>
    <edit-line :important="true" label="职务" v-model="expwork.cPosition"></edit-line>
    <edit-line :important="false" label="证明人及职务" v-model="expwork.cDescrlong"></edit-line>
    <edit-line :important="true" label="离职原因" v-model="expwork.cTerReason"></edit-line>
    <div class="btn_region">
      <div class="submit-btn" @click="save">保存</div>
      <div class="remove-btn" @click="remove"> {{expwork.cSeqno ? '删除' : '取消'}} </div>
    </div>
    <div stype="width:100%;height:30px">&nbsp;</div>
  </div>

</template>

<script>
import CommonUtil from '../../../../components/basic/util'
import EditLine from '../../../../components/basic/EditLine'
import EditDateLine from '../../../../components/basic/EditDateLine'
import { saveWork,delWork } from '../../../../api/api'
import { json2Form } from '../../../../util/http'

export default {

  name: 'input-information',
  components: {
    EditLine, EditDateLine
  },
  data() {
    return {
      expwork:{
        rsHireId: '',
        startDt:''
      },
    }
  },
  created() {
    this.getexps()
    if(this.$store.state.hid){
      this.expwork.rsHireId = this.$store.state.hid
    }
  },
  methods: {
    save() {
      const that = this
      if(!CommonUtil.valid(this, this.expwork,"startDt","请选择开始时间") 
        || !CommonUtil.valid(this, this.expwork,"endDt","请选择结束时间") 
        || !CommonUtil.valid(this, this.expwork,"cCompany","请输入工作单位") 
        || !CommonUtil.valid(this, this.expwork,"cPosition","请输入职务") 
        || !CommonUtil.valid(this, this.expwork,"cTerReason","请输入离职原因") 
        ){
        return;
      }
      if(this.expwork.startDt > this.expwork.endDt) {
        this.$vux.alert.show({
          title: '提示',
          content: '结束日期须晚于等于开始日期',
        })
        return;
      }
      console.log(that.expwork)
      saveWork(json2Form(that.expwork)).then(res => {
        //成功：000000
        if(res && res.retCode === '000000' ){
          //保存成功
          this.$vux.alert.show({
            title: '提示',
            content: '保存成功',
            onHide () {
              that.$router.push('/informationCollection/userInfo');
            }
          })

        }else{
          this.$vux.alert.show({
            title: '提示',
            content: res.retMsg
          })
        }
      }).catch (res=>{
        this.$vux.alert.show({
          title: '警告',
          content: '网络异常，请稍后重试'
        })
      })

    },
    remove() {
      if(!this.expwork.cSeqno) {
        this.$router.push('/informationCollection/userInfo');
      }
      const _this = this;
      _this.$vux.confirm.show({
          // 组件除show外的属性
          title: '提示',
          content: '确定删除？',
          onCancel () {
          },
          onConfirm () {
            delWork(json2Form({
              rsHireId: _this.expwork.rsHireId,
              cSeqno: _this.expwork.cSeqno
            })).then(res=>{
              //成功：000000
              if(res && res.retCode === '000000' ){
                  _this.$router.push('/informationCollection/userInfo');
              }else{
                _this.$vux.alert.show({
                  title: '提示',
                  content: res.retMsg
                })
              }

            })
            .catch(res=>{
              _this.$vux.alert.show({

                })
            })

          }
        })

    },
    getexps() {
      if(this.$route.params.workexp){
        this.expwork = this.$route.params.workexp
      }
      CommonUtil.fillDateEmpty(this.expwork, ['startDt','endDt'])
    }
  }
}
</script>
<style type="text/scss" lang="scss">
@import "./editinfo";
.vux-cell-value,.vux-cell-placeholder{ color: #000;font-size:13px; }
</style>
